/** Copyright 2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.spring4facelets.security.ui;

import javax.faces.component.UIComponent;

/**
 * General static utility class providing connivence methods for manipulating
 * jsf.
 *
 * @author Allen Parslow
 */
final class FacesUtils {

    public static final String NO_PROPERTY = null;

    private FacesUtils() {
        // prevent instances
    }

    /**
     * Retrieves the value of an integer attribute from a UIComponent.
     *
     * @param uiComponent
     *            The ui component to interrogate.
     * @param attributeName
     *            The attribute to retrieve.
     *
     * @return A Integer containing the attribute's value.
     */
    public static Integer getIntegerAtttribute(UIComponent uiComponent, String attributeName) {
        Integer result = null;
        Object object = uiComponent.getAttributes().get(attributeName);
        if (object instanceof Integer) {
            result = (Integer) object;
        }
        return result;
    }

    /**
     * Retrieves the value of an string attribute from a UIComponent.
     *
     * @param uiComponent
     *            The ui component to interrogate.
     * @param attributeName
     *            The attribute to retrieve.
     *
     * @return A String containing the attribute's value.
     */
    public static String getStringAttribute(UIComponent uiComponent, String attributeName) {
        String result = null;
        Object object = uiComponent.getAttributes().get(attributeName);
        if (object instanceof String) {
            result = (String) object;
        }
        return result;
    }
}
